package com.meelive.ingkee.push.platform.xiaomi;

import android.content.Context;
import android.text.TextUtils;
import android.util.Log;

import com.meelive.ingkee.push.InkePushConfig;
import com.meelive.ingkee.push.InkePushHelper;
import com.meelive.ingkee.push.model.InkePushType;
import com.meelive.ingkee.push.common.PushUtils;
import com.meelive.ingkee.push.platform.IPush;
import com.xiaomi.mipush.sdk.MiPushClient;

import static com.meelive.ingkee.push.model.Constance.TAG;

/**
 * Create by: fanfeiyue
 * on: 2019-08-22
 * desc:
 * 文档: https://dev.mi.com/console/doc/detail?pId=41
 */
public class InkeMiPush extends IPush {
    @Override
    public InkePushType getPushType() {
        return InkePushType.MIPUSH;
    }

    @Override
    public void onRegister(Context context, InkePushConfig config) {
        if (PushUtils.DEBUG) {
            Log.d(TAG, "InkeMiPush onRegister");
        }
        String regId = MiPushClient.getRegId(context);
        if (TextUtils.isEmpty(regId)) {
            MiPushClient.registerPush(context, config.getMiAppId(), config.getMiAppKey());
        } else {
            InkePushHelper.getInstance().onReceiveToken(getPushType(), regId);
        }
    }

    @Override
    public void onUnregister(Context context, InkePushConfig config) {
        MiPushClient.unregisterPush(context);
    }
}
